import {Router} from 'vue-router'
import list from '@/router/routes'

// 白名单
const whiteList:Set<string> = new Set(list)
export const permission = (router: Router) => {
  router.beforeEach((to, _, next) => {
    const token: string = sessionStorage.getItem('token')!
    if (token) {
      if (<"login">to.name === "login") {
        next("/")
      }else {
        next()
      }
    }
    else {
      if (whiteList.has(<string>to.name)) {
        next()
      }else {
        next({name: 'login'})
      }
    }
  })
}
